package com.mlxg.selver.domain.base;

import cn.dev33.satoken.stp.StpUtil;
import com.fasterxml.jackson.annotation.JsonFormat;

import java.io.Serializable;
import java.util.Date;

/**
 * @author cy zhang
 * @version 1.0
 * @date 2025/4/9 16:18
 * Entity基类
 */
public class BaseEntity implements Serializable {
    private static final long serialVersionUID = 1L;

    /** 创建者 */
    private String createBy;

    /** 创建时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date createTime;

    /** 更新者 */
    private String updateBy;

    /** 更新时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "Asia/Shanghai")
    private Date updateTime;

    public String getCreateBy() {
        return createBy;
    }

    public void setCreateBy(String createBy) {
        this.createBy = createBy;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUpdateBy() {
        return updateBy;
    }

    public void setUpdateBy(String updateBy) {
        this.updateBy = updateBy;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public static  <T> void setCommonFields(T entity) {
        if (entity instanceof BaseEntity) {
            BaseEntity baseEntity = (BaseEntity) entity;
            baseEntity.setCreateBy((String) StpUtil.getLoginId());
            baseEntity.setUpdateBy((String) StpUtil.getLoginId());
            baseEntity.setCreateTime(new Date());
            baseEntity.setUpdateTime(new Date());
        }
    }

    public static  <T> void setCommonFieldUpdate(T entity) {
        if (entity instanceof BaseEntity) {
            BaseEntity baseEntity = (BaseEntity) entity;
            baseEntity.setUpdateBy((String) StpUtil.getLoginId());
            baseEntity.setUpdateTime(new Date());
        }
    }

    /**
     * 删除标记（0：正常；1：删除；2：审核；-1:驳回）
     */
    public static final String DEL_FLAG_NORMAL = "0";
    public static final String DEL_FLAG_DELETE = "1";
    public static final String DEL_FLAG_AUDIT = "2";
    public static final String DEL_FLAG_REFUSE = "-1";
    /**
     * 审核标记（0:审核通过；-1:审核不通过；2:审核中，-2:已保存未申请提交审核）
     */
    public static final String AUDIT_FLAG_NORMAL = "0";
    public static final String AUDIT_FLAG_REFUSE = "-1";
    public static final String AUDIT_FLAG_AUDIT = "2";
    public static final String AUDIT_FLAG_SAVEDANDNOTSUBMITTEDFORREVIEW = "-2";

    /**
     * 审核标记（1:审核通过；2:审核不通过；0:审核中,-1保存未提交的）
     */
    public static final Integer AUDIT_FLAG_NORMALS = 0;
    public static final Integer AUDIT_FLAG_REFUSES = 2;
    public static final Integer AUDIT_FLAG_AUDITS = 1;
    public static final Integer AUDIT_FLAG_SAVE = -1;

    /**
     * 删除标记（1：正常；0：删除）
     */
    public static final Integer DEL_FLAG_NORMALS = 1;
    public static final Integer DEL_FLAG_DELETES = 0;

}
